<template>
<view class="parlist">
	<block v-for="(item, index) in pjList" :key="index" v-if="tyid==1">
		<view class="paritem">
			<view class="par_img">
				<image mode="aspectFill" class="pimg" :src="item.img_str[0]"></image>
			</view>
			<view class="par_word">
				<view class="p_tit">{{item.title}}</view>
				<view class="p_cont">{{item.content}}</view>
				<view class="p_more">
					<view class="time">{{item.address!=null&&item.address!=''?item.address:''}}</view>
					<view class="more" @tap="click_toDet" :data-id="item.id">查看详情</view>
				</view>
			</view>
		</view>
	</block>
	<block v-for="(item, index) in pjList" :key="index" v-if="tyid==2">
		<view class="paritem">
			<view class="par_img">
				<image mode="aspectFill" class="pimg" :src="item.img_str[0]"></image>
			</view>
			<view class="par_word">
				<view class="p_tit">{{item.title}}</view>
				<view class="p_cont1">{{item.content}}</view>
				<view class="p_more">
					<view class="time">{{item.createtime}}</view>
					<view class="more" @tap="click_toDet" :data-id="item.id">查看详情</view>
				</view>
				<view class="butt_box">
					<label class="delet" :data-id="item.id" :data-index="index" @tap="delPart">删除</label>
					<label :data-id="item.id" @tap="updatePart">编辑</label>
				</view>
			</view>
		</view>
	</block>
	<view class="noMore" v-if="is_show==1">没有更多了...</view>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      leftid: 1,
      pjList: [],
      is_show: 0,
      tyid: ''
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      tyid: options.tid
    });

    if (options.tid == 1) {
      wx.setNavigationBarTitle({
        title: '配件列表'
      }), that.getPJlist();
    } else {
      wx.setNavigationBarTitle({
        title: '我的配件库'
      }), that.getMyList();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.tyid == 1) {
      that.getPJlist();
    } else {
      that.getMyList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    //修改配件信息
    updatePart: function (e) {
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pagesA/parts/parts?tid=2&id=' + id
      });
    },
    //删除配件
    delPart: function (e) {
      var that = this;
      var id = e.currentTarget.dataset.id;
      var index = e.currentTarget.dataset.index;
      console.log(index);
      wx.showModal({
        title: '提示',
        content: '是否确定删除此条信息？',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            console.log('确认');
            app.globalData.util.request({
              url: "entry/wxapp/Api",
              data: {
                m: "monai_market",
                r: "home.index.userdel_sbk",
                uid: app.globalData.getuid(),
                id: id
              },
              cachetime: "0",
              success: function (res) {
                console.log('删除返回', res.data);
                var arr = that.pjList;
                arr.splice(index, 1);
                that.setData({
                  pjList: arr
                });
              }
            });
          } else {
            console.log('取消');
          }
        }
      });
    },
    //点击查看详情
    click_toDet: function (e) {
      var that = this;
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pagesA/partDet/partDet?id=' + id
      });
    },
    // 获取我的配件列表
    getMyList: function () {
      var that = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "home.index.usersbklist",
          leftid: that.leftid++,
          uid: app.globalData.getuid()
        },
        cachetime: "0",
        success: function (res) {
          console.log('配件列表：', res.data);

          if (res.data.data.length != 0) {
            that.setData({
              pjList: that.pjList.concat(res.data.data)
            });
          } else {
            that.setData({
              is_show: 1
            });
          }
        }
      });
    },
    //获取平台配件列表
    getPJlist: function () {
      var that = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_market",
          r: "home.index.ptsbkList",
          leftid: that.leftid++
        },
        cachetime: "0",
        success: function (res) {
          console.log('配件列表：', res.data);

          if (res.data.data.length != 0) {
            that.setData({
              pjList: that.pjList.concat(res.data.data)
            });
          } else {
            that.setData({
              is_show: 1
            });
          }
        }
      });
    }
  }
};
</script>
<style>
@import "./partList.css";
</style>